package com.game.center.service.manager;

import com.game.center.common.CenterServerErrorCode;
import com.game.framework.dao.entity.AccountEntity;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 */
public class AccountRegisterManager {


    public AccountEntity buildAccount(String account, String password, String loginIp) {
        AccountEntity accountEntity = new AccountEntity();
        accountEntity.setUserId(System.currentTimeMillis()+ RandomUtils.nextLong());
        accountEntity.setAccount(account);
        accountEntity.setPassword(password);
        accountEntity.setRegisterIp(loginIp);
        accountEntity.setCreateTime(new Date());
        return accountEntity;
    }

    public void checkAccount(String account) {
        if (StringUtils.isBlank(account)) {
            throw CenterServerErrorCode.USERNAME_NULL.newException();
        }
        int len = account.length();
        //正式中可以将此处修改为从配置中读取
        if (len > 20 || len < 5) {
            throw CenterServerErrorCode.USERNAME_LENGTH_ERROR.newException();
        }
        //TODO 非法字符验证也要添加
        //以及其它的检测验证
    }

    public void checkPassword(String password) {
        if (StringUtils.isBlank(password)) {
            throw CenterServerErrorCode.PASSWORD_NULL.newException();
        }
        int len = password.length();
        if (len > 20 || len < 5) {
            throw CenterServerErrorCode.PASSWORD_LENGTH_ERROR.newException();
        }
        //TODO 添加其它验证
    }


}
